<?php
/*
 *	CRM中呼叫录音通过vipfile下载
 */
require_once dirname(dirname(__FILE__)) . '/include/common.inc.php';
require_once INCLUDE_ROOT_PATH . 'file_server.class.php';
$secret_key = '3493TF&jiayuan78';
$cl_id = isset($_REQUEST['cl_id']) ? $_REQUEST['cl_id'] : '';	//对应的资源ID
$date = isset($_REQUEST['date']) ? $_REQUEST['date'] : '';	//呼叫发起时间
$res = isset($_REQUEST['res']) ? $_REQUEST['res'] : '';	//要操作的文件名
$sign = isset($_REQUEST['sign']) ? $_REQUEST['sign'] : ''; //签名
$dirname = !empty($_REQUEST['dirname']) ? $_REQUEST['dirname'] : 'YUNHU'; //录音存储文件夹名称
if ($sign != md5($secret_key.'cl_id='.$cl_id.'date='.$date))
{
    echo 'error：sign fail';
    exit;
}
if (empty($date))
{
    echo 'error：A parameter of date is null';
    exit;
}
$date1 = date('Y-m-d',$date);
$date2 = date('Y-m',$date);
$filepath = CALLREC_ROOT_PATH.$dirname.'/'.$date2.'/'.$date1.'/'.$cl_id.'.mp3';
if($res == 'show')
{
	echo $filepath;
	exit;
}
$File_server = new File_server();
$result = '';
if (file_exists($filepath))
{
	$result = $File_server->download($filepath);
}
echo json_encode($result);
?>